{% extends 'base.twig' %}

{% block content %}
<ul class="nav nav-tabs" role="tablist">
  <li role="presentation" class="active"><a href="#tab-containers" aria-controls="tab-containers" role="tab" data-toggle="tab">{{ lang.debug.system_containers }}</a></li>
  <li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">{{ lang.debug.logs }}
      <span class="caret"></span></a>
    <ul class="dropdown-menu">
      <li role="presentation"><span class="dropdown-desc">{{ lang.debug.in_memory_logs }}</span></li>
      <li role="presentation"><a href="#tab-postfix-logs" aria-controls="tab-postfix-logs" role="tab" data-toggle="tab">Postfix</a></li>
      <li role="presentation"><a href="#tab-dovecot-logs" aria-controls="tab-dovecot-logs" role="tab" data-toggle="tab">Dovecot</a></li>
      <li role="presentation"><a href="#tab-sogo-logs" aria-controls="tab-sogo-logs" role="tab" data-toggle="tab">SOGo</a></li>
      <li role="presentation"><a href="#tab-netfilter-logs" aria-controls="tab-netfilter-logs" role="tab" data-toggle="tab">Netfilter</a></li>
      <li role="presentation"><a href="#tab-autodiscover-logs" aria-controls="tab-autodiscover-logs" role="tab" data-toggle="tab">Autodiscover</a></li>
      <li role="presentation"><a href="#tab-watchdog-logs" aria-controls="tab-watchdog-logs" role="tab" data-toggle="tab">Watchdog</a></li>
      <li role="presentation"><a href="#tab-acme-logs" aria-controls="tab-acme-logs" role="tab" data-toggle="tab">ACME</a></li>
      <li role="presentation"><a href="#tab-api-logs" aria-controls="tab-api-logs" role="tab" data-toggle="tab">API</a></li>
      <li role="presentation"><a href="#tab-api-rl" aria-controls="tab-api-rl" role="tab" data-toggle="tab">Ratelimits</a></li>
      <li role="presentation"><span class="dropdown-desc">{{ lang.debug.external_logs }}</span></li>
      <li role="presentation"><a href="#tab-rspamd-history" aria-controls="tab-rspamd-history" role="tab" data-toggle="tab">Rspamd</a></li>
      <li role="presentation"><span class="dropdown-desc">{{ lang.debug.static_logs }}</span></li>
      <li role="presentation"><a href="#tab-ui" aria-controls="tab-ui" role="tab" data-toggle="tab">Mailcow UI</a></li>
      <li role="presentation"><a href="#tab-sasl" aria-controls="tab-sasl" role="tab" data-toggle="tab">SASL</a></li>
    </ul>
  </li>
</ul>

<div class="row">
  <div class="col-md-12">
    <div class="tab-content" style="padding-top:20px">
      <div class="debug-log-info">{{ lang.debug.log_info|format(log_lines+1)|raw }}</div>
      <div role="tabpanel" class="tab-pane active" id="tab-containers">
        <div class="panel panel-default">
          <div class="panel-heading">
            <h3 class="panel-title">{{ lang.debug.disk_usage }}</h3>
          </div>
          <div class="panel-body">
            <div class="row">
              <div class="col-sm-3">
                <p><i class="bi bi-hdd-fill"></i> {{ vmail_df[0] }}</p>
                <p>{{ vmail_df[2] }} / {{ vmail_df[1] }} ({{ vmail_df[4] }})</p>
              </div>
              <div class="col-sm-9">
                <div class="progress">
                  <div class="progress-bar progress-bar-info" role="progressbar" style="width:{{ vmail_df[4] }}"></div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="panel panel-default">
          <div class="panel-heading">
            <h3 class="panel-title">{{ lang.debug.solr_status }}</h3>
          </div>
          <div class="panel-body">
            <div class="row">
              <div class="col-sm-3">
                <p><img class="img-responsive" alt="Solr Logo" width="128px" src="" /></p>
              </div>
              <div class="col-sm-9">
                {% if solr_status != false %}
                <div class="progress">
                  <div class="progress-bar progress-bar-info" role="progressbar" style="width:{{ solr_status.jvm.memory.raw['used%']|round }}%"></div>
                </div>
                <p>{{ lang.debug.jvm_memory_solr }}: {{ (solr_status.jvm.memory.total - solr_status.jvm.memory.free) }} / {{ solr_status.jvm.memory.total }}
                  ({{ solr_status.jvm.memory.raw['used%']|round }}%)</p>
                <hr>
                <p>{{ lang.debug.uptime }}: {{ solr_uptime }}h</p>
                <p>{{ lang.debug.started_at }}: <span class="parse_date">{{ solr_status.status['dovecot-fts'].startTime }}</span></p>
                <p>{{ lang.debug.last_modified }}: <span class="parse_date">{{ solr_status.status['dovecot-fts'].index.lastModified }}</span></p>
                <p>{{ lang.debug.size }}: {{ solr_status.status['dovecot-fts'].index.size }}</p>
                <p><i class="bi bi-file-text"></i> {{ lang.debug.docs }}: {{ solr_status.status['dovecot-fts'].index.numDocs }}</p>
                {% else %}
                <p>{{ lang.debug.solr_dead }}</p>
                {% endif %}
              </div>
            </div>
          </div>
        </div>
        <div class="panel panel-default">
          <div class="panel-heading">
            <h3 class="panel-title">{{ lang.debug.containers_info }}</h3>
          </div>
          <div class="panel-body">
            <ul class="list-group">
              {% for container, container_info in containers %}
                <li class="list-group-item">
                  {{ container }} ({{ container_info.Config.Image }})
                  <br class="visible-xs" />
                  <small>({{ lang.debug.started_on }} <span class="parse_date">{{ container_info.State.StartedAtHR }}</span>)</small>
                  <a href data-toggle="modal" data-container="{{ container }}" data-target="#RestartContainer" class="pull-right btn btn-xs btn-default">{{ lang.debug.restart_container }}
                    <i class="pull-right bi
                    {% if container_info.State.Running == 1 %}
                    bi-record-fill text-success
                    {% elseif container_info.State %}
                    bi-record-fill text-danger
                    {% else %}
                    default
                    {% endif %}
                    "
                    ></i></a>
                </li>
              {% endfor %}
            </ul>
          </div>
        </div>
      </div>

      <div role="tabpanel" class="tab-pane" id="tab-postfix-logs">
        <div class="panel panel-xs-lg panel-default">
          <div class="panel-heading">Postfix <span class="badge badge-info table-lines"></span>
            <div class="btn-group pull-right">
              <button class="btn btn-xs btn-xs-lg btn-default add_log_lines" data-post-process="general_syslog" data-table="postfix_log" data-log-url="postfix" data-nrows="100">+ 100</button>
              <button class="btn btn-xs btn-xs-lg btn-default add_log_lines" data-post-process="general_syslog" data-table="postfix_log" data-log-url="postfix" data-nrows="1000">+ 1000</button>
              <button class="btn btn-xs btn-xs-lg btn-default refresh_table" data-draw="draw_postfix_logs" data-table="postfix_log">{{ lang.admin.refresh }}</button>
            </div>
          </div>
          <div class="panel-body">
            <div class="table-responsive">
              <table class="table table-striped table-condensed" id="postfix_log"></table>
            </div>
          </div>
        </div>
      </div>

      <div role="tabpanel" class="tab-pane" id="tab-ui">
        <div class="panel panel-xs-lg panel-default">
          <div class="panel-heading"> Mailcow UI <span class="badge badge-info table-lines"></span>
            <div class="btn-group pull-right">
              <button class="btn btn-xs btn-xs-lg btn-default add_log_lines" data-post-process="mailcow_ui" data-table="ui_logs" data-log-url="ui" data-nrows="1000">+ 1000</button>
              <button class="btn btn-xs btn-xs-lg btn-default add_log_lines" data-post-process="mailcow_ui" data-table="ui_logs" data-log-url="ui" data-nrows="10000">+ 10000</button>
              <button class="btn btn-xs btn-xs-lg btn-default refresh_table" data-draw="draw_ui_logs" data-table="ui_logs">{{ lang.admin.refresh }}</button>
            </div>
          </div>
          <div class="panel-body">
            <div class="table-responsive">
              <table class="table table-striped table-condensed" id="ui_logs"></table>
            </div>
          </div>
        </div>
      </div>

      <div role="tabpanel" class="tab-pane" id="tab-sasl">
        <div class="panel panel-xs-lg panel-default">
          <div class="panel-heading">SASL <span class="badge badge-info table-lines"></span>
            <div class="btn-group pull-right">
              <button class="btn btn-xs btn-xs-lg btn-default add_log_lines" data-post-process="sasl_log_table" data-table="sasl_logs" data-log-url="ui" data-nrows="1000">+ 1000</button>
              <button class="btn btn-xs btn-xs-lg btn-default add_log_lines" data-post-process="sasl_log_table" data-table="sasl_logs" data-log-url="ui" data-nrows="10000">+ 10000</button>
              <button class="btn btn-xs btn-xs-lg btn-default refresh_table" data-draw="draw_sasl_logs" data-table="sasl_logs">{{ lang.admin.refresh }}</button>
            </div>
          </div>
          <div class="panel-body">
            <div class="table-responsive">
              <table class="table table-striped table-condensed" id="sasl_logs"></table>
            </div>
          </div>
        </div>
      </div>

      <div role="tabpanel" class="tab-pane" id="tab-dovecot-logs">
        <div class="panel panel-xs-lg panel-default">
          <div class="panel-heading">Dovecot <span class="badge badge-info table-lines"></span>
            <div class="btn-group pull-right">
              <button class="btn btn-xs btn-xs-lg btn-default add_log_lines" data-post-process="general_syslog" data-table="dovecot_log" data-log-url="dovecot" data-nrows="100">+ 100</button>
              <button class="btn btn-xs btn-xs-lg btn-default add_log_lines" data-post-process="general_syslog" data-table="dovecot_log" data-log-url="dovecot" data-nrows="1000">+ 1000</button>
              <button class="btn btn-xs btn-xs-lg btn-default refresh_table" data-draw="draw_dovecot_logs" data-table="dovecot_log">{{ lang.admin.refresh }}</button>
            </div>
          </div>
          <div class="panel-body">
            <div class="table-responsive">
              <table class="table table-striped table-condensed" id="dovecot_log"></table>
            </div>
          </div>
        </div>
      </div>

      <div role="tabpanel" class="tab-pane" id="tab-sogo-logs">
        <div class="panel panel-xs-lg panel-default">
          <div class="panel-heading">SOGo <span class="badge badge-info table-lines"></span>
            <div class="btn-group pull-right">
              <button class="btn btn-xs btn-xs-lg btn-default add_log_lines" data-post-process="general_syslog" data-table="sogo_log" data-log-url="sogo" data-nrows="100">+ 100</button>
              <button class="btn btn-xs btn-xs-lg btn-default add_log_lines" data-post-process="general_syslog" data-table="sogo_log" data-log-url="sogo" data-nrows="1000">+ 1000</button>
              <button class="btn btn-xs btn-xs-lg btn-default refresh_table" data-draw="draw_sogo_logs" data-table="sogo_log">{{ lang.admin.refresh }}</button>
            </div>
          </div>
          <div class="panel-body">
            <div class="table-responsive">
              <table class="table table-striped table-condensed" id="sogo_log"></table>
            </div>
          </div>
        </div>
      </div>

      <div role="tabpanel" class="tab-pane" id="tab-netfilter-logs">
        <div class="panel panel-xs-lg panel-default">
          <div class="panel-heading">Netfilter <span class="badge badge-info table-lines"></span>
            <div class="btn-group pull-right">
              <button class="btn btn-xs btn-xs-lg btn-default add_log_lines" data-post-process="general_syslog" data-table="netfilter_log" data-log-url="netfilter" data-nrows="100">+ 100</button>
              <button class="btn btn-xs btn-xs-lg btn-default add_log_lines" data-post-process="general_syslog" data-table="netfilter_log" data-log-url="netfilter" data-nrows="1000">+ 1000</button>
              <button class="btn btn-xs btn-xs-lg btn-default refresh_table" data-draw="draw_netfilter_logs" data-table="netfilter_log">{{ lang.admin.refresh }}</button>
            </div>
          </div>
          <div class="panel-body">
            <div class="table-responsive">
              <table class="table table-striped table-condensed" id="netfilter_log"></table>
            </div>
          </div>
        </div>
      </div>

      <div role="tabpanel" class="tab-pane" id="tab-rspamd-history">
        <div class="panel panel-xs-lg panel-default">
          <div class="panel-heading">Rspamd history <span class="badge badge-info table-lines"></span>
            <div class="btn-group pull-right">
              <button class="btn btn-xs btn-xs-lg btn-default add_log_lines" data-post-process="rspamd_history" data-table="rspamd_history" data-log-url="rspamd-history" data-nrows="100">+ 100</button>
              <button class="btn btn-xs btn-xs-lg btn-default add_log_lines" data-post-process="rspamd_history" data-table="rspamd_history" data-log-url="rspamd-history" data-nrows="1000">+ 1000</button>
              <button class="btn btn-xs btn-xs-lg btn-default refresh_table" data-draw="draw_rspamd_history" data-table="rspamd_history">{{ lang.admin.refresh }}</button>
            </div>
          </div>
          <div class="panel-body">
            <legend>{{ lang.debug.chart_this_server }}</legend>
            <div id="chart-container">
              <canvas id="rspamd_donut" style="width:100%;height:400px"></canvas>
            </div>
            <legend>{{ lang.debug.history_all_servers }}</legend>
            <div class="table-responsive">
              <table class="table table-striped table-condensed log-table" id="rspamd_history"></table>
            </div>
          </div>
        </div>
      </div>

      <div role="tabpanel" class="tab-pane" id="tab-autodiscover-logs">
        <div class="panel panel-xs-lg panel-default">
          <div class="panel-heading">Autodiscover <span class="badge badge-info table-lines"></span>
            <div class="btn-group pull-right">
              <button class="btn btn-xs btn-xs-lg btn-default add_log_lines" data-post-process="autodiscover_log" data-table="autodiscover_log" data-log-url="autodiscover" data-nrows="100">+ 100</button>
              <button class="btn btn-xs btn-xs-lg btn-default add_log_lines" data-post-process="autodiscover_log" data-table="autodiscover_log" data-log-url="autodiscover" data-nrows="1000">+ 1000</button>
              <button class="btn btn-xs btn-xs-lg btn-default refresh_table" data-draw="draw_autodiscover_logs" data-table="autodiscover_log">{{ lang.admin.refresh }}</button>
            </div>
          </div>
          <div class="panel-body">
            <div class="table-responsive">
              <table class="table table-striped table-condensed" id="autodiscover_log"></table>
            </div>
          </div>
        </div>
      </div>

      <div role="tabpanel" class="tab-pane" id="tab-watchdog-logs">
        <div class="panel panel-xs-lg panel-default">
          <div class="panel-heading">Watchdog <span class="badge badge-info table-lines"></span>
            <div class="btn-group pull-right">
              <button class="btn btn-xs btn-xs-lg btn-default add_log_lines" data-post-process="watchdog" data-table="watchdog_log" data-log-url="watchdog" data-nrows="100">+ 100</button>
              <button class="btn btn-xs btn-xs-lg btn-default add_log_lines" data-post-process="watchdog" data-table="watchdog_log" data-log-url="watchdog" data-nrows="1000">+ 1000</button>
              <button class="btn btn-xs btn-xs-lg btn-default refresh_table" data-draw="draw_watchdog_logs" data-table="watchdog_log">{{ lang.admin.refresh }}</button>
            </div>
          </div>
          <div class="panel-body">
            <div class="table-responsive">
              <table class="table table-striped table-condensed" id="watchdog_log"></table>
            </div>
          </div>
        </div>
      </div>

      <div role="tabpanel" class="tab-pane" id="tab-acme-logs">
        <div class="panel panel-xs-lg panel-default">
          <div class="panel-heading">ACME <span class="badge badge-info table-lines"></span>
            <div class="btn-group pull-right">
              <button class="btn btn-xs btn-xs-lg btn-default add_log_lines" data-post-process="general_syslog" data-table="acme_log" data-log-url="acme" data-nrows="100">+ 100</button>
              <button class="btn btn-xs btn-xs-lg btn-default add_log_lines" data-post-process="general_syslog" data-table="acme_log" data-log-url="acme" data-nrows="1000">+ 1000</button>
              <button class="btn btn-xs btn-xs-lg btn-default refresh_table" data-draw="draw_acme_logs" data-table="acme_log">{{ lang.admin.refresh }}</button>
            </div>
          </div>
          <div class="panel-body">
            <div class="table-responsive">
              <table class="table table-striped table-condensed" id="acme_log"></table>
            </div>
          </div>
        </div>
      </div>

      <div role="tabpanel" class="tab-pane" id="tab-api-logs">
        <div class="panel panel-xs-lg panel-default">
          <div class="panel-heading">API <span class="badge badge-info table-lines"></span>
            <div class="btn-group pull-right">
              <button class="btn btn-xs btn-xs-lg btn-default add_log_lines" data-post-process="apilog" data-table="api_log" data-log-url="api" data-nrows="100">+ 100</button>
              <button class="btn btn-xs btn-xs-lg btn-default add_log_lines" data-post-process="apilog" data-table="api_log" data-log-url="api" data-nrows="1000">+ 1000</button>
              <button class="btn btn-xs btn-xs-lg btn-default refresh_table" data-draw="draw_api_logs" data-table="api_log">{{ lang.admin.refresh }}</button>
            </div>
          </div>
          <div class="panel-body">
            <div class="table-responsive">
              <table class="table table-striped table-condensed" id="api_log"></table>
            </div>
          </div>
        </div>
      </div>

      <div role="tabpanel" class="tab-pane" id="tab-api-rl">
        <div class="panel panel-xs-lg panel-default">
          <div class="panel-heading">Ratelimits <span class="badge badge-info table-lines"></span>
            <div class="btn-group pull-right">
              <button class="btn btn-xs btn-xs-lg btn-default add_log_lines" data-post-process="rllog" data-table="rl_log" data-log-url="ratelimited" data-nrows="100">+ 100</button>
              <button class="btn btn-xs btn-xs-lg btn-default add_log_lines" data-post-process="rllog" data-table="rl_log" data-log-url="ratelimited" data-nrows="1000">+ 1000</button>
              <button class="btn btn-xs btn-xs-lg btn-default refresh_table" data-draw="draw_rl_logs" data-table="rl_log">{{ lang.admin.refresh }}</button>
            </div>
          </div>
          <div class="panel-body">
            <p class="help-block">{{ lang.admin.hash_remove_info }}</p>
            <div class="table-responsive">
              <table class="table table-striped table-condensed" id="rl_log"></table>
            </div>
          </div>
        </div>
      </div>

    </div> <!-- /tab-content -->
  </div> <!-- /col-md-12 -->
</div> <!-- /row -->

<script type='text/javascript'>
  var lang = {{ lang_admin|raw }};
  var csrf_token = '{{ csrf_token }}';
  var log_pagination_size = '{{ log_pagination_size }}';
</script>
{% endblock %}
